package com.service.product.impl;

import java.util.List;

import com.dao.ProductCategoryDao;
import com.entity.Product;
import com.entity.ProductCategory;
import com.service.product.ProductCategoryService;
import com.utils.MybatisUtil;

public class ProductCategoryServiceImpl implements ProductCategoryService{

	@Override
	/**
	 * 一级
	 */
	public List<ProductCategory> finProductCategoryListOne() {
		ProductCategoryDao pro = MybatisUtil.getMapper(ProductCategoryDao.class);
		List<ProductCategory> list = pro.ProductCategoryListOne();
		MybatisUtil.closeCommit();
		return list;
	}

	@Override
	/**
	 * 二级
	 */
	public List<ProductCategory> finProductCategoryListTwo() {
		ProductCategoryDao pro = MybatisUtil.getMapper(ProductCategoryDao.class);
		List<ProductCategory> list = pro.ProductCategoryListTwo();
		MybatisUtil.closeCommit();
		return list;
	}

	@Override
	/**
	 * 三级
	 */
	public List<ProductCategory> finProductCategoryListThree() {
		ProductCategoryDao pro = MybatisUtil.getMapper(ProductCategoryDao.class);
		List<ProductCategory> list = pro.ProductCategoryListThree();
		MybatisUtil.closeCommit();
		return list;
	}

	@Override
	public int finDelProductById(int id) {
		ProductCategoryDao pro = MybatisUtil.getMapper(ProductCategoryDao.class);
		int row = pro.delProductById(id);
		MybatisUtil.closeCommit();
		return row;
	}

	@Override
	public int finAddProduct(Product product) {
		ProductCategoryDao pro = MybatisUtil.getMapper(ProductCategoryDao.class);
		int row = -1;
		if(product == null) {
			row = pro.addProduct(product);
		}else {
			row = pro.updateProduct(product);
		}
		MybatisUtil.closeCommit();
		return row;
	}

	@Override
	public List<ProductCategory> getProductCategoryListByparentId(int typeId, int parentId) {
		ProductCategoryDao pro = MybatisUtil.getMapper(ProductCategoryDao.class);
		List<ProductCategory> list = pro.getProductCategoryListByparentId(typeId, parentId);
		MybatisUtil.closeCommit();
		return list;
	}
	
	

}
